'use strict'

let koa=require("koa");
let bodyparser=require('koa-bodyparser');
let controller = require('./controllers');
let templating = require('./templating');
let staticRes=require('koa-static');
let session=require('./session');
let models = require('./models');
let app=new koa();

//引入session自定义模块
app.use(session(app));

//静态文件处理
app.use(staticRes(__dirname+'/statics'));
app.use(staticRes(__dirname+'/img'));
app.use(staticRes(__dirname+'/utils'));

//注册中间件 注意先注册post请求的解释器，后注册路由
app.use(bodyparser());

//注册模板引擎
app.use(templating)

//注册路由
app.use(controller());



(async ()=>{
     await models.sync();
})();



app.listen(5001);
console.log(`http://127.0.0.1:5001`);